/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package WekaModels;

import grex.Data.ArffTableModel;
import grex.ErrorManager;
import grex.Prediction;
import grex.PredictionContainer;
import java.util.logging.Level;
import java.util.logging.Logger;
import weka.classifiers.functions.MultilayerPerceptron;
import weka.classifiers.trees.REPTree;
import weka.core.Instance;
import weka.core.Instances;

/**
 *
 * @author RIK
 */
public class GrexMLP extends WekaPredictiveModel{
    MultilayerPerceptron mlp;
    
    public GrexMLP(ArffTableModel data){
        super(data,new MultilayerPerceptron());
        mlp = (MultilayerPerceptron) model;
    }
    

    public double getNrOfNodes() {
            return mlp.getHiddenLayers().length();
    }
    public void execute(PredictionContainer pc) {
        for (Prediction p : pc.values()) {

            try {
                Instance instance = wekaArffTableModel.getInstance(p.getInstance(), wekaTrain);//wekaTrain is just used to set the Dataset in the instance
                double prediction;
                prediction = Math.max(model.classifyInstance(instance), 0);

                p.setProbs(model.distributionForInstance(instance));
                p.setPrediction(prediction);

            } catch (Exception ex) {
                ErrorManager.getInstance().reportError(ex);
            }

        }
    }
    
    public String getName() {
        return "MLP"; 
    }
    
}
